package org.boyan.modules.service.impl;

import org.boyan.entity.trans.TransCode;
import org.boyan.modules.mapper.TransCodeMapper;
import org.boyan.modules.service.TransCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

@Service
public class TransCodeImpl implements TransCodeService {
    @Autowired
    private TransCodeMapper transCodeMapper;

    //批量新增交易码
    @Override
    public int addTransCodeList(List<TransCode> transCodeList) {
        //先去重,使用迭代器的方式遍历删除list，防止ConcurrentModificationException以及删除不干净的问题
        Iterator<TransCode> iterator=transCodeList.listIterator();
        while (iterator.hasNext()){
            TransCode transCode=iterator.next();
            if(transCodeMapper.isExist(transCode)>0){
                iterator.remove();
            }
        }
        int ret=0;
        if(transCodeList.size()!=0){
                ret=transCodeMapper.addTransCodeList(transCodeList);
        }
        return ret;
    }
}
